﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Campus {
    public abstract class AttackAbility : Ability {
        private int m_lastAttackTime;
        protected int LastAttackTime {
            get { return m_lastAttackTime; }
            set { m_lastAttackTime = value; }
        }
        private int m_attackInterval;
        public int AttackInterval {
            get { return m_attackInterval; }
        }
        private int m_minDamage;
        public int MinimumDamage {
            get { return m_minDamage; }
        }
        private int m_maxDamage;
        public int MaximumDamage {
            get { return m_maxDamage; }
        }

        public AttackAbility(AbilityMenuIcon menuIcon, BaseEntity owner, Animation animation, TargetTypes targetType,
                int minDamage, int maxDamage, int attackInterval)
                : base(menuIcon, owner, animation, targetType) {
            m_minDamage = minDamage;
            m_maxDamage = maxDamage;
            m_lastAttackTime = 0;
            m_attackInterval = attackInterval;
            MenuDelegate = delegate(string option) {
                                                Campus.cursor.ActionState = CursorActionState.attack;
                                                Campus.cursor.ClickMethod = delegate(Vector2 gamePoint) {
                                                    if (TargetType == TargetTypes.BaseEntityTarget) {
                                                        Target = Cursor.GetBaseEntityAtPoint(gamePoint, Owner.PlayerOwner);
                                                    } else if (TargetType == TargetTypes.PointTarget) {
                                                        Target = gamePoint;
                                                    }
                                                    Owner.SetCurrentAbility(this);
                                                    Campus.cursor.ClickMethod = null;
                                                    Campus.cursor.ActionState = CursorActionState.idle;
                                                };
                                            };
        }
        public AttackAbility(AttackAbility copySource)
            : base(copySource) {
            m_attackInterval = copySource.m_attackInterval;
            m_minDamage = copySource.m_minDamage;
            m_maxDamage = copySource.m_maxDamage;
            MenuDelegate = delegate(string option) {
                Campus.cursor.ActionState = CursorActionState.attack;
                Campus.cursor.ClickMethod = delegate(Vector2 gamePoint) {
                    if (TargetType == TargetTypes.BaseEntityTarget) {
                        Target = Cursor.GetBaseEntityAtPoint(gamePoint, Owner.PlayerOwner);
                    } else if (TargetType == TargetTypes.PointTarget) {
                        Target = gamePoint;
                    }
                    Owner.SetCurrentAbility(this);
                    Campus.cursor.ClickMethod = null;
                    Campus.cursor.ActionState = CursorActionState.idle;
                };
            };
        }

        protected bool IsTargetValid() {
            if (Target == null) {
                return false;
            }
            if (Target is BaseEntity) {
                if (((BaseEntity)Target).CurrentHP <= 0) {
                    Target = null;
                    return false;
                }
            }
            return true;
        }

        public abstract override Ability Clone();
        public abstract override void Update(Microsoft.Xna.Framework.GameTime gameTime, bool checkInput, bool updateBoundingBox);
    }
}